package sealte.hvpms.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import sealte.hvpms.dao.AdminDAO;
import sealte.hvpms.dao.impl.AdminDAOImpl;

public class AdminAdd extends HttpServlet {
	private static final long serialVersionUID = 1L;

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html");
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		
		String name = request.getParameter("admin_name");
		String password = request.getParameter("admin_password");
		AdminDAO ab = new AdminDAOImpl();
		String message = "";
		boolean isNameExist = ab.isNameExist(name);
		if(!isNameExist){
			boolean flag = ab.addNew(name, password);
			if(flag){
				message = "添加成功";
			}else{
				message = "添加失败！！";
			}
		}else{
			message = "相同账号已存在，请换用其他账号！";
		}
		request.setAttribute("message_addNew", message);
		request.getRequestDispatcher("hvpms_admin/admin_management.jsp").forward(request, response);
	}
}
